package pe.com.fondam.sgp.core.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.stereotype.Repository;

import pe.com.fondam.sgp.core.commons.bs.JpaBaseDAOImpl;
import pe.com.fondam.sgp.core.dao.TablaGeneralDAO;
import pe.com.fondam.sgp.core.domain.TablaGeneral;

@Repository
public class TablaGeneralDAOImpl extends JpaBaseDAOImpl implements TablaGeneralDAO {

	@Autowired
	public TablaGeneralDAOImpl(
			@Qualifier("jpaTemplate") JpaTemplate jpaTemplate) {
		this.setJpaTemplate(jpaTemplate);
	}
	
	@Override
	public TablaGeneral findTablaGeneralById(Integer id) {
		return super.findById(TablaGeneral.class, id);
	}

	@Override
	public TablaGeneral findTablaGeneralByPrefijo(String prefijo) {
		TablaGeneral tablaGeneral = null;
		String queryString = "from TablaGeneral where prefijo = ? ";
		Object[] params = new Object[1];
		params[0] = prefijo;
		List<TablaGeneral> listTablaGeneral = super.find(queryString, params);
		if(!listTablaGeneral.isEmpty()){
			tablaGeneral = listTablaGeneral.get(0);
		}
		return tablaGeneral;
	}

}
